
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>odespy.rkc &mdash; Odespy API 0.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/pyramid.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="Odespy API 0.2 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Neuton&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Nobile:regular,italic,bold,bolditalic&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="../../_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->

  </head>
  <body>

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Odespy API 0.2 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for odespy.rkc</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;Module for wrapping rkc.f.&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">solvers</span> <span class="kn">import</span> <span class="n">Solver</span><span class="p">,</span> <span class="n">Adaptive</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>

<span class="c"># f_f77 and other items are defined in odepack.py and will</span>
<span class="c"># be populated in solvers._parameters in any import of odepack.</span>
<span class="c"># We just need to add what rkc.py and that is not defined elsewhere:</span>

<span class="n">_parameters_RKC</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>

    <span class="n">spcrad</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
        <span class="n">help</span><span class="o">=</span><span class="s">&#39;Python function of (u, t) returning the spectral radius &#39;</span>\
             <span class="s">&#39;of the Jacobian in the rkc.f solver.&#39;</span><span class="p">,</span>
        <span class="nb">type</span><span class="o">=</span><span class="nb">callable</span><span class="p">),</span>

    <span class="n">spcrad_f77</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
        <span class="n">help</span><span class="o">=</span><span class="s">&#39;&#39;&#39;Fortran version of spcrad function.</span>
<span class="s">This subroutine should be defined in form:</span>

<span class="s">        double precision function spcrad_f77</span>
<span class="s">       1  (neq,t,u)</span>
<span class="s">  Cf2py intent(hide)  neq</span>
<span class="s">        integer       neq</span>
<span class="s">        double precision t,u(neq)</span>
<span class="s">        spcrad_f77 =</span>
<span class="s">        return</span>
<span class="s">        end</span>

<span class="s">&#39;&#39;&#39;</span><span class="p">,</span>
        <span class="nb">type</span><span class="o">=</span><span class="nb">callable</span><span class="p">),</span>
    <span class="p">)</span>

<span class="kn">import</span> <span class="nn">solvers</span>
<span class="n">solvers</span><span class="o">.</span><span class="n">_parameters</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">_parameters_RKC</span><span class="p">)</span>

<div class="viewcode-block" id="RKC"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC">[docs]</a><span class="k">class</span> <span class="nc">RKC</span><span class="p">(</span><span class="n">Adaptive</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Wrapper for rkc.f, a well-known Fortran ODE solver.</span>

<span class="sd">    Besides the standard attributes of class ``Solver``, class ``RKC``</span>
<span class="sd">    also stores a dictionary ``statistics``, which contains data and</span>
<span class="sd">    explanations from the execution of the ``RKC`` subroutine.</span>

<span class="sd">    The Fortran source code can be obtained from netlib and contains</span>
<span class="sd">    more details. For convenience we quote here from ``rkc.f`` the</span>
<span class="sd">    main description of the method:</span>

<span class="sd">    &quot;ABSTRACT:  RKC integrates initial value problems for systems of first</span>
<span class="sd">    order ordinary differential equations.  It is based on a family of</span>
<span class="sd">    explicit Runge-Kutta-Chebyshev formulas of order two.  The stability</span>
<span class="sd">    of members of the family increases quadratically in the number of</span>
<span class="sd">    stages m. An estimate of the spectral radius is used at each step to</span>
<span class="sd">    select the smallest m resulting in a stable integration. RKC is</span>
<span class="sd">    appropriate for the solution to modest accuracy of mildly stiff problems</span>
<span class="sd">    with eigenvalues of Jacobians that are close to the negative real axis.</span>
<span class="sd">    For such problems it has the advantages of explicit one-step methods and</span>
<span class="sd">    very low storage. If it should turn out that RKC is using m far beyond</span>
<span class="sd">    100, the problem is not mildly stiff and alternative methods should be</span>
<span class="sd">    considered.  Answers can be obtained cheaply anywhere in the interval</span>
<span class="sd">    of integration by means of a continuous extension evaluated in the</span>
<span class="sd">    subroutine RKCINT.</span>

<span class="sd">    The initial value problems arising from semi-discretization of</span>
<span class="sd">    diffusion-dominated parabolic partial differential equations and of</span>
<span class="sd">    reaction-diffusion equations, especially in two and three spatial</span>
<span class="sd">    variables, exemplify the problems for which RKC was designed.&quot; (rkc.f)</span>

<span class="sd">    This wrapper does not call ``RKCINT`` but runs ``RKC`` between each</span>
<span class="sd">    time interval specified by the ``time_points`` array sent to the</span>
<span class="sd">    ``solve`` method.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">quick_description</span> <span class="o">=</span> \
        <span class="s">&quot;Explicit 2nd-order Runge-Kutta-Chebyshev method (rkc.f)&quot;</span>

    <span class="n">_optional_parameters</span> <span class="o">=</span> <span class="n">Adaptive</span><span class="o">.</span><span class="n">_optional_parameters</span> <span class="o">+</span> \
        <span class="p">[</span><span class="s">&#39;f_f77&#39;</span><span class="p">,</span> <span class="s">&#39;spcrad&#39;</span><span class="p">,</span> <span class="s">&#39;spcrad_f77&#39;</span><span class="p">,</span> <span class="s">&#39;jac_constant&#39;</span><span class="p">]</span>
    <span class="c"># The following step parameters are illegal for rkc.f</span>
    <span class="n">_optional_parameters</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;first_step&#39;</span><span class="p">)</span>
    <span class="n">_optional_parameters</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;min_step&#39;</span><span class="p">)</span>
    <span class="n">_optional_parameters</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;max_step&#39;</span><span class="p">)</span>

    <span class="n">_idid_messages</span> <span class="o">=</span> <span class="p">{</span>
        <span class="mi">3</span><span class="p">:</span>
        <span class="s">&#39;Repeated improper error control: For some j, &#39;</span>
        <span class="s">&#39;ATOL(j) = 0 and Y(j) = 0.&#39;</span><span class="p">,</span>
        <span class="mi">4</span><span class="p">:</span>
        <span class="s">&#39;Unable to achieve the desired accuracy with the precision available. &#39;</span>
        <span class="s">&#39;A severe lack of smoothness in the solution y(t) or the function &#39;</span>
        <span class="s">&#39;f(t,y) is likely.&#39;</span><span class="p">,</span>
        <span class="mi">6</span><span class="p">:</span>
        <span class="s">&#39;The method used by RKC to estimate the spectral radius of the &#39;</span>
        <span class="s">&#39;Jacobian failed to converge.&#39;</span><span class="p">,</span>
        <span class="mi">0</span><span class="p">:</span>
        <span class="s">&#39;Iteration stops when function TERMINATE return with True.&#39;</span><span class="p">,</span>
        <span class="mi">1</span><span class="p">:</span><span class="s">&#39;Iteration succeed.&#39;</span>
        <span class="p">}</span>

<div class="viewcode-block" id="RKC.adjust_parameters"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.adjust_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">adjust_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parameters</span><span class="p">[</span><span class="s">&#39;rtol&#39;</span><span class="p">][</span><span class="s">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parameters</span><span class="p">[</span><span class="s">&#39;rtol&#39;</span><span class="p">][</span><span class="s">&#39;range&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="mf">2.22e-15</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="RKC.check_atol"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.check_atol">[docs]</a>    <span class="k">def</span> <span class="nf">check_atol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39; ATOL need to be supplied as scalar or vector of length NEQ. &#39;&#39;&#39;</span>
        <span class="n">atol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atol</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atol</span><span class="p">,</span><span class="nb">float</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">atol</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">neq</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span>  <span class="s">&#39;&#39;&#39;</span>
<span class="s">ATOL =</span><span class="si">%s</span><span class="s"> should be either a scalar or a vector of length NEQ=</span><span class="si">%d</span><span class="s">.</span>
<span class="s">           &#39;&#39;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">atol</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">neq</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="RKC.validate_data"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.validate_data">[docs]</a>    <span class="k">def</span> <span class="nf">validate_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_atol</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">Adaptive</span><span class="o">.</span><span class="n">validate_data</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="RKC.initialize_for_solve"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.initialize_for_solve">[docs]</a>    <span class="k">def</span> <span class="nf">initialize_for_solve</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># INFO(4) is an integer array to specify how the problem</span>
        <span class="c"># is to be solved</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>      <span class="c"># Compute solution at each time point</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;spcrad_f77&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;spcrad&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>  <span class="c"># SPCRAD routine is supplied</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spcrad</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span> <span class="mf">0.0</span>  <span class="c"># dummy function</span>
        <span class="c"># Is the Jacobian constant?</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jac_constant</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">iterable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atol</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atol</span><span class="p">)</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">neq</span><span class="p">)):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>   <span class="c"># ATOL is a sequence of length NEQ</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;f&#39;</span><span class="p">):</span>
            <span class="c"># If f is input in form of a Python function f(u,t),</span>
            <span class="c"># let self.f_f77 wrap f and have arguments t, u.</span>
            <span class="n">f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">f</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">f_f77</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">t</span><span class="p">,</span><span class="n">u</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">u</span><span class="p">,</span><span class="n">t</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;f_f77&#39;</span><span class="p">):</span>
            <span class="c"># The right-hand side &quot;f&quot; is input as a Fortran function</span>
            <span class="c"># taking the arguments t,u.</span>
            <span class="c"># Set self.f to be f_f77 wrapped to the general form f(u,t)</span>
            <span class="c"># for switch_to().</span>
            <span class="n">f_f77</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">f_f77</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">u</span><span class="p">,</span><span class="n">t</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">f_f77</span><span class="p">(</span><span class="n">t</span><span class="p">,</span><span class="n">u</span><span class="p">))</span>
        <span class="c"># If spcrad is input in form of spcrad(u,t),</span>
        <span class="c"># wrap spcrad to spcrad_f77 for Fortran code.</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;spcrad&#39;</span><span class="p">):</span>
            <span class="c"># If spcrad is in form of spcrad(u,t), wrap for Fortran code.</span>
            <span class="n">spcrad</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spcrad</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spcrad_f77</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">t</span><span class="p">,</span><span class="n">u</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">spcrad</span><span class="p">(</span><span class="n">u</span><span class="p">,</span><span class="n">t</span><span class="p">))</span>

        <span class="c"># We call Solver and not Adaptive below because Adaptive</span>
        <span class="c"># just computes first_step, min_step and max_step, all of</span>
        <span class="c"># which are non-used parameters for rkc.f</span>
        <span class="n">Solver</span><span class="o">.</span><span class="n">initialize_for_solve</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>   <span class="c"># Common settings</span>
</div>
<div class="viewcode-block" id="RKC.initialize"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.initialize">[docs]</a>    <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Import extension module _rkc and check that it exists.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">_rkc</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span> <span class="o">=</span> <span class="n">_rkc</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">&#39;Cannot find the extension module _rkc.</span><span class="se">\n</span><span class="s">Remove build directory, run setup.py again and investigate why _rkc.so was not successfully built.&#39;</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="RKC.solve"><a class="viewcode-back" href="../../rkc.html#odespy.rkc.RKC.solve">[docs]</a>    <span class="k">def</span> <span class="nf">solve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">time_points</span><span class="p">,</span> <span class="n">terminate</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="c"># flag to indicate dummy function</span>
        <span class="n">itermin</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">terminate</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">)</span>
        <span class="c"># Logical value cannot be transferred with f2py.</span>
        <span class="k">if</span> <span class="n">terminate</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>    <span class="c"># Dummy function</span>
            <span class="n">terminate_int</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">u</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">step_no</span><span class="p">,</span> <span class="n">nt</span><span class="p">,</span> <span class="n">neq</span><span class="p">:</span> <span class="mi">0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">terminate_int</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">u</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">step_no</span><span class="p">,</span> <span class="n">nt</span><span class="p">,</span> <span class="n">neq</span><span class="p">:</span> \
                                   <span class="nb">int</span><span class="p">(</span><span class="n">terminate</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">step_no</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">time_points</span><span class="p">)</span>

        <span class="c"># Setting for internal parameters, (like self.u)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">initialize_for_solve</span><span class="p">()</span>

        <span class="c"># Validity-check for values of class attributes</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">validate_data</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;Invalid data in &quot;</span><span class="si">%s</span><span class="s">&quot;:</span><span class="se">\n</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                             <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                              <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">)))</span>

        <span class="c"># Call extension module</span>
        <span class="n">solve</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">solve</span>
        <span class="c"># Fortran or Python function</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">f_f77</span><span class="p">,</span> <span class="s">&#39;_cpointer&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">f_f77</span><span class="p">)</span>
        <span class="n">spcrad</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spcrad_f77</span><span class="p">,</span> <span class="s">&#39;_cpointer&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">spcrad_f77</span><span class="p">)</span>

        <span class="c"># Start iteration</span>
        <span class="n">uout</span><span class="p">,</span> <span class="n">idid</span><span class="p">,</span> <span class="n">nstop</span> <span class="o">=</span> <span class="n">solve</span><span class="p">(</span><span class="n">spcrad</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span>
                                  <span class="bp">self</span><span class="o">.</span><span class="n">t</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rtol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">atol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">,</span>
                                  <span class="n">terminate_int</span><span class="p">,</span> <span class="n">itermin</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">idid</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>   <span class="c"># abnormal status?</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;idid=</span><span class="si">%d</span><span class="s"> &gt; 1 (abort)&#39;</span> <span class="o">%</span> <span class="n">idid</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">idid</span> <span class="o">=</span> <span class="s">&#39;idid=</span><span class="si">%d</span><span class="se">\n</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">idid</span><span class="p">,</span> <span class="n">RKC</span><span class="o">.</span><span class="n">_idid_messages</span><span class="p">[</span><span class="n">idid</span><span class="p">])</span>

        <span class="c"># Store statistics from common block</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;nfe&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">nfe</span><span class="p">,</span>
                    <span class="s">&#39;number of evaluations of f used to integrate &#39;</span>
                    <span class="s">&#39;the initial value problem&#39;</span><span class="p">),</span>
            <span class="s">&#39;nsteps&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">nsteps</span><span class="p">,</span>
                       <span class="s">&#39;no of integration steps&#39;</span><span class="p">),</span>
            <span class="s">&#39;naccpt&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">naccpt</span><span class="p">,</span>
                       <span class="s">&#39;no of accepted steps&#39;</span><span class="p">),</span>
            <span class="s">&#39;nrejct&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">nrejct</span><span class="p">,</span>
                       <span class="s">&#39;no of rejected steps&#39;</span><span class="p">),</span>
            <span class="s">&#39;nfesig&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">nfesig</span><span class="p">,</span>
                       <span class="s">&#39;no of evaluations of f used to estimate &#39;</span>
                       <span class="s">&#39;spectral radius&#39;</span><span class="p">),</span>
            <span class="s">&#39;maxm&#39;</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_rkc</span><span class="o">.</span><span class="n">rkcdid</span><span class="o">.</span><span class="n">maxm</span><span class="p">,</span>
                     <span class="s">&#39;max no of stages used&#39;</span><span class="p">)}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">uout</span><span class="p">[:</span><span class="n">nstop</span><span class="p">,:])</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="c"># self.u is two-dimensional, remove 2nd dimension if scalar ODE</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="o">.</span><span class="n">size</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">t</span>
</pre></div></div></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Odespy API 0.2 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Liwei Wang and Hans Petter Langtangen.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>